package networkbackend;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.LinkedList;

/**
 * 
 * @author dgambone
 */

public class NetworkMon_Logger extends Thread {

	protected javax.swing.event.EventListenerList listenerList = new javax.swing.event.EventListenerList();

	public static void LogIt(LinkedList<PacketNode> The_Packets) {
		try {
			// This For Loop is for testing purposes. -DG
			for (PacketNode A_Packet : The_Packets) {
				WriteCSV(A_Packet);
			}
		} catch (Exception e) {// Catch exception if any
			System.err.println("Error: " + e.getMessage());
		}
	}

	public void AddThisPacket(PacketNode The_Info) {
		WriteCSV(The_Info);
	}

	public static void WriteCSV(PacketNode The_Info) {
		try {
			FileWriter fstream = new FileWriter("c:\\NetworkMon.csv", true);
			BufferedWriter out = new BufferedWriter(fstream);
			out.write(The_Info.destinationAddress + ","
					+ The_Info.destinationPort + "," + The_Info.length + ","
					+ The_Info.protocol + "," + The_Info.recName + ","
					+ The_Info.sendersName.toString() + ","
					+ The_Info.sourceAddress + "," + The_Info.sourcePort + ","
					+ The_Info.getListLabel() + " \n");
			// Close the output stream
			out.close();
		} catch (Exception e) {// Catch exception if any
			System.err.println("Error: " + e.getMessage());
		}

	}

	@Override
	public void run() {

	}

	public void Finish_Him() {

	}

}
